const jsonData = {

}
export default {
    namespaced: true,
    state: {
        jsonData: {

        },
        curPage: {
            // 页面标题
            title: '',
            // 页面路径
            path: '/',
            // 404是重定向到默认页面
            isDefault: '',
            // 页面配置
            config: {
                /** 背景图片 */
                bgImage: '',
                /** 背景颜色 */
                bgColor: '',
                /** 是否缓存当前页面 */
                keepAlive: false,
            },
            // 当前页面的所有组件
            blocks: [],
        },
        curBlocks: [],
        curRoute: '',
        curSelectIdx: -1,

    },
    getters: {
        focusBlock(state) {
            let focus = [];
            let unfocused = [];
            state.curBlocks.forEach(block => (block.focus ? focus : unfocused).push(block));
            return focus[0] || null;
            // return { focus, unfocused }

        },
    },
    actions: {

    },
    mutations: {
        setBlock(state, { type, block, newIndex, oldIndex }) {
            switch(type) {
                case 'add':
                    state.curBlocks.splice(newIndex,0,block)
                    break;
                case 'move':
                    let oldBlock = state.curBlocks.splice(oldIndex, 1, state.curBlocks[newIndex])[0];
                    state.curBlocks.splice(newIndex, 1, oldBlock);
                    break;
            }
        },
        /**
         * focus 相关
         */
        clearBlockFocus(state) {
            state.curBlocks.forEach(block => block.focus = false);
        },
        setBlockFocus(state, uuid) {
            state.curBlocks.forEach(block => {
                if(block.uuid === uuid) {
                    block.focus = true
                    return;
                }
                block.focus = false
            })
        },

    }
}